package com.sky.controller.admin;

import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.DishService;
import com.sky.vo.DishVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/admin/dish")
@Slf4j
@Api(tags = "菜品相关接口")
public class DishController {

    @Autowired
    private DishService dishService;

    /**
     * 新增菜品
     * @param dishDTO
     * @return
     */
    @PostMapping
    @ApiOperation(value = "新增菜品")
    public Result AddDish(@RequestBody DishDTO dishDTO){
        dishService.AddDishFlover(dishDTO);
        return Result.success();
    }

    /**
     * 菜品分页查询
     */
    @GetMapping("/page")
    @ApiOperation(value = "分页查询菜品")
    public Result<PageResult> DishPage(DishPageQueryDTO dishPageQueryDTO){
        PageResult pageResult=dishService.DishPage(dishPageQueryDTO);
        return Result.success(pageResult);
    }

    /**
     * 删除菜品
     */
    @DeleteMapping
    @ApiOperation(value = "删除菜品")
    public Result DeleteDish(@RequestParam List<Long> ids){
        log.info("删除菜品",ids);
        dishService.DeleteDish(ids);
        return Result.success();
    }

    /**
     * 菜品起售停售
     */
    @PostMapping("/status/{status}")
    @ApiOperation(value = "起售停售菜品")
    public Result StartORForb(@PathVariable Integer status,Long id){
        log.info("起售停售菜品",status);
        dishService.StartORForb(status,id);
        return Result.success();
    }

    /**
     * 根据ID查询菜品
     */
    @GetMapping("/{id}")
    @ApiOperation(value = "根据ID查询菜品信息")
    public Result<DishVO> DishIDQuery(@PathVariable Long id){
        log.info("查询菜品信息",id);
        DishVO dishVO=dishService.DishIDQuery(id);
        return Result.success(dishVO);
    }

    /**
     * 修改菜品信息
     */
    @PutMapping
    @ApiOperation(value = "修改新的菜品数据")
    public Result UpdateNewDish(@RequestBody DishDTO dishDTO){
        log.info("修改菜品信息");
        dishService.UpdateNewDish(dishDTO);
        return Result.success();
    }
}
